package edu.upc.clase.demo.dao.impl;

import edu.upc.clase.demo.dao.ComentarDao;
import edu.upc.clase.demo.entity.Comentar;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Omar
 */
@Repository
public class ComentarDaoImpl extends SimpleJdbcDaoSupport implements ComentarDao {

    private static Logger log = LoggerFactory.getLogger(ComentarDaoImpl.class);

    @Autowired
    public ComentarDaoImpl(DataSource dataSource) {
        log.info("Asignando el dataSource");
        setDataSource(dataSource);
    }

    @Override
    public Integer insertar(Comentar comentar) {
        getJdbcTemplate().update("insert into ZCOMMENT(FECREG,NROITEM,IDLOCAL,IDCAN,BOXTEX,CALIF1,CALIF2,CALIF3,CALIF4,CALIF5) "
                + " values (sysdate,?,?,?,?,?,?,?,?,?)",
                comentar.getNROITEM(), comentar.getIDLOCAL(), comentar.getIDCAN(), comentar.getBOXTEX(),
                comentar.getCALIF1(), comentar.getCALIF2(), comentar.getCALIF3(), comentar.getCALIF4(), comentar.getCALIF5());
        return getSimpleJdbcTemplate().queryForInt("call identity()");
    }
}
